﻿<style>
    .notice-read {
        background-color: #c6e6ff;
    }
</style>
<div id="notice-layout">
    <table class="layui-hide" id="table-notice" lay-filter="table-notice"></table>
</div>
<script type="text/javascript">
    var table = null;
    layui.use('table', function () {
        table = layui.table;
        table.render({
            elem: '#table-notice'
            , url: '../notice/list'
            , cols: [[
                {field: 'content', title: '内容'}
            ]]
            , page: {
                layout: ['prev', 'next'],
                prev: '上一页',
                next: '下一页',
            }
            ,limit:20
            , done: function () {
                workUtils.height("#notice-layout .layui-table-body", 30);
                $(".notice-read").each(function () {
                    var cla = $(this).parent('.layui-table-cell');
                    cla.addClass("notice-read");
                    cla.attr("data-id", $(this).attr("data-id"))
                    $(this).removeClass("notice-read");
                });
            }
            , height: 'full-55'
            , cell: function (field, item) {
                return buildHtml(item);
            }
        });
    });
    function buildHtml(item) {
        var html = '<div class="title notice-title ' + (item.readed ? "" : "notice-read") + '" data-id="' + item.id + '">' + item.content + '</div>';
        html += '<div class="layui-row">';
        html += '<div class="layui-col-md5">';
        html += workUtils.toDate(item.created,'yyyy-MM-dd hh');
        html += '</div>';
        html += '<div class="layui-col-md7" style="text-align: right">';
        html += item.noticeType;
        if (item.noteType == 'invite' && item.refId != null) {
            html += '<a class="layui-btn layui-btn-xs projectok-btn" data-id="' + item.id + '" lay-event="edit">确认</a>';
        }
        html += '</div>';
        html += '</div>';
        html += '</div>';
        return html;
    }


    workUtils.onclick(".projectok-btn", function (c) {
        var id = $(c).attr("data-id");
        workUtils.ajaxPost("../notice/okproject", {
            id: id
        });
        $(c).remove();
    });
    workUtils.onclick(".notice-read", function (c) {
        var id = $(c).attr("data-id");
        workUtils.ajaxPost("../notice/ok", {
            id: id
        });
        $(c).removeClass("notice-read");
    });
</script>